




using Microsoft.EntityFrameworkCore;
using Mysql.Model;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllers();

builder.Services.AddDbContext<Wode>(options=>{
    var conners =
    builder.Configuration.GetConnectionString("DefaultConnection");
    options.UseMySql(conners,ServerVersion.AutoDetect(conners));
});


var app = builder.Build();

using(var scope = app.Services.CreateScope()){
    var services = scope.ServiceProvider;
    var context = services.GetRequiredService<Wode>();
    context.Database.EnsureCreated();
    SeedData(context);
}

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

static void SeedData(Wode wode){
    wode.Blogs.AddRange(
        new Blog { Id = 1, Name = "2", Age = "3" }
    );
    wode.SaveChanges();
}


